#include <lib3d/node/Void.h>

namespace liba {
namespace lib3d {
namespace node {

const Atom Void::node_name("Void");

Void::Void(const Atom& name, Node* parent)
	: Node2D(name, parent)
{ }

Void::Void(const Void& rhs)
	: Node2D(rhs)
	, dimensions(rhs.dimensions)
	, anchor(rhs.anchor)
{ }

Void::~Void()
{
}

Node* Void::Clone()
{
	return new Void(*this);
}

bool Void::on_attribute(xml::Provider * prov, const std::string & name, const std::string & value)
{
	if (name == "Width")
		return converter::convert(value, &this->dimensions.x);
	else if (name == "Height")
		return converter::convert(value, &this->dimensions.y);
	else if (name == "Dimensions")
		return converter::convert(value, &this->dimensions);
	else if (name == "Anchor")
		return converter::convert(value, &this->anchor);

	return Node2D::on_attribute(prov, name, value);
}

math::Rect<float> Void::GetLocalBounds()
{
	math::Vector2<float> leftBottom(-dimensions.x * anchor.x, -dimensions.y * anchor.y);
	return math::Rect<float>(
		leftBottom.x,
		leftBottom.y,
		dimensions.x,
		dimensions.y);
}

} // namespace node
} // namespace lib3d
} // namespace liba